home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / FWShLiSh.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  10.4 KB  |  317 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWShLiSh.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWSHLISH_H
  13. #include "FWShLiSh.h"
  14. #endif
  15.  
  16. // ----- Foundation Includes -----
  17.  
  18. #ifndef FWSTREAM_H
  19. #include "FWStream.h"
  20. #endif
  21.  
  22. //========================================================================================
  23. // File scope definitions
  24. //========================================================================================
  25.  
  26. #ifdef FW_BUILD_MAC
  27. #pragma segment FWGraphics_ShapeListShape
  28. #endif
  29.  
  30. //========================================================================================
  31. //    class FW_CShapeListShape
  32. //========================================================================================
  33.  
  34. FW_DEFINE_AUTO(FW_CShapeListShape)
  35. FW_DEFINE_CLASS_M1(FW_CShapeListShape, FW_CShape)
  36.  
  37. // This class is archivable, but we provide the archiving implementation in a separate
  38. // translation unit in order to enable deadstripping of the archiving-related code
  39. // in parts that do not use archiving with this class.
  40.  
  41. //----------------------------------------------------------------------------------------
  42. // FW_CShapeListShape::FW_CShapeListShape
  43. //----------------------------------------------------------------------------------------
  44.  
  45. FW_CShapeListShape::FW_CShapeListShape(const FW_PShapeList& list) :
  46.     FW_CShape(FW_kFrame, FW_kNormalInk, FW_kNormalStyle, FW_kNormalFont),
  47.     fShapeList(list)
  48. {
  49.     FW_END_CONSTRUCTOR
  50. }
  51.  
  52. //----------------------------------------------------------------------------------------
  53. // FW_CShapeListShape::FW_CShapeListShape
  54. //----------------------------------------------------------------------------------------
  55.  
  56. FW_CShapeListShape::FW_CShapeListShape(FW_CReadableStream& stream) :
  57.     FW_CShape(stream),
  58.     fShapeList(stream)
  59. {
  60.     FW_END_CONSTRUCTOR
  61. }
  62.  
  63. //----------------------------------------------------------------------------------------
  64. // FW_CShapeListShape::FW_CShapeListShape
  65. //----------------------------------------------------------------------------------------
  66.  
  67. FW_CShapeListShape::FW_CShapeListShape(const FW_CShapeListShape& other) :
  68.     FW_CShape(FW_kFrame, FW_kNormalInk, FW_kNormalStyle, FW_kNormalFont),
  69.     fShapeList(other.fShapeList)
  70. {
  71.     FW_END_CONSTRUCTOR
  72. }
  73.  
  74. //----------------------------------------------------------------------------------------
  75. // FW_CShapeListShape::~FW_CShapeListShape
  76. //----------------------------------------------------------------------------------------
  77.  
  78. FW_CShapeListShape::~FW_CShapeListShape()
  79. {
  80.     FW_START_DESTRUCTOR
  81. }
  82.  
  83. //----------------------------------------------------------------------------------------
  84. // FW_CShapeListShape::HitTestList
  85. //----------------------------------------------------------------------------------------
  86.  
  87. FW_CShape* FW_CShapeListShape::HitTestList(FW_CGraphicContext& gc,
  88.                                            const FW_CPoint& test,
  89.                                            FW_Fixed tolerance) const
  90. {
  91.     // Shapes are rendered in reverse order of the list so I need to test them from
  92.     // first (frontmost) to last (backmost)
  93.     FW_CShapeListIterator ite(fShapeList);
  94.     for (FW_CShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  95.     {
  96.         if(shape->HitTest(gc, test, tolerance))
  97.             return shape;
  98.     }    
  99.     return NULL;
  100. }
  101.  
  102. //----------------------------------------------------------------------------------------
  103. // FW_CShapeListShape::operator=
  104. //----------------------------------------------------------------------------------------
  105.  
  106. FW_CShapeListShape& FW_CShapeListShape::operator=(const FW_CShapeListShape& other)
  107. {
  108.     fShapeList = other.fShapeList;
  109.     return *this;
  110. }
  111.  
  112. //----------------------------------------------------------------------------------------
  113. // FW_CShapeListShape::GetShapeList
  114. //----------------------------------------------------------------------------------------
  115.  
  116. const FW_PShapeList& FW_CShapeListShape::GetShapeList() const
  117. {
  118.     return fShapeList;
  119. }
  120.  
  121. //----------------------------------------------------------------------------------------
  122. // FW_CShapeListShape::GetShapeList
  123. //----------------------------------------------------------------------------------------
  124.  
  125. FW_PShapeList& FW_CShapeListShape::GetShapeList()
  126. {
  127.     return fShapeList;
  128. }
  129.  
  130. //----------------------------------------------------------------------------------------
  131. // FW_CShapeListShape::GetUnSharedShapeList
  132. //----------------------------------------------------------------------------------------
  133.  
  134. FW_PShapeList& FW_CShapeListShape::GetUnSharedShapeList()
  135. {
  136.     if (fShapeList->GetReferenceCount() > 1)
  137.         fShapeList = fShapeList.Copy();
  138.  
  139.     return fShapeList;
  140. }
  141.  
  142. //----------------------------------------------------------------------------------------
  143. // FW_CShapeListShape::SetShapeList
  144. //----------------------------------------------------------------------------------------
  145.  
  146. void FW_CShapeListShape::SetShapeList(const FW_PShapeList& list)
  147. {
  148.     fShapeList = list;
  149. }
  150.  
  151. //----------------------------------------------------------------------------------------
  152. // FW_CShapeListShape::Purge
  153. //----------------------------------------------------------------------------------------
  154.  
  155. void FW_CShapeListShape::Purge()
  156. {
  157.     fShapeList->Purge();
  158. }
  159.  
  160. //----------------------------------------------------------------------------------------
  161. // FW_CShapeListShape::Render
  162. //----------------------------------------------------------------------------------------
  163.  
  164. void FW_CShapeListShape::Render(FW_CGraphicContext& gc) const
  165. {
  166.     // Draw shapes in reverse order of the list
  167.     if (GetRenderVerb() != FW_kNoRendering) 
  168.         FW_CShapeListShape::RenderShapeList(gc, fShapeList);
  169. }
  170.  
  171. //----------------------------------------------------------------------------------------
  172. // FW_CShapeListShape::Render
  173. //----------------------------------------------------------------------------------------
  174.  
  175. void FW_CShapeListShape::RenderShapeList(FW_CGraphicContext& gc,
  176.                                          const FW_PShapeList& shapeList)
  177. {
  178.     // Draw shapes in reverse order of the list
  179.     FW_CShapeListIterator ite(shapeList);
  180.     for (FW_CShape* shape = ite.Last(); ite.IsNotComplete(); shape = ite.Previous())
  181.     {
  182.         shape->Render(gc);
  183.     }    
  184. }
  185.  
  186. //----------------------------------------------------------------------------------------
  187. // FW_CShapeListShape::Copy
  188. //----------------------------------------------------------------------------------------
  189.  
  190. FW_CShape* FW_CShapeListShape::Copy() const
  191. {
  192.     return FW_NEW(FW_CShapeListShape, (*this));
  193. }
  194.  
  195. //----------------------------------------------------------------------------------------
  196. // FW_CShapeListShape::HitTest
  197. //----------------------------------------------------------------------------------------
  198.  
  199. FW_Boolean FW_CShapeListShape::HitTest(FW_CGraphicContext& gc,
  200.                                         const FW_CPoint& test,
  201.                                         FW_Fixed tolerance) const
  202. {
  203.     if (GetRenderVerb() == FW_kNoRendering)
  204.         return NULL;
  205.  
  206.     return HitTestList(gc, test, tolerance) != NULL;
  207. }
  208.  
  209. //----------------------------------------------------------------------------------------
  210. // FW_CShapeListShape::Transform
  211. //----------------------------------------------------------------------------------------
  212.  
  213. void FW_CShapeListShape::Transform(Environment *ev, ODTransform* transform)
  214. {
  215.     FW_CShapeListIterator ite(fShapeList);
  216.     for (FW_CShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  217.     {
  218.         shape->Transform(ev, transform);
  219.     }    
  220. }
  221.  
  222. //----------------------------------------------------------------------------------------
  223. // FW_CShapeListShape::InverseTransform
  224. //----------------------------------------------------------------------------------------
  225.  
  226. void FW_CShapeListShape::InverseTransform(Environment *ev, ODTransform* transform)
  227. {
  228.     FW_CShapeListIterator ite(fShapeList);
  229.     for (FW_CShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  230.     {
  231.         shape->InverseTransform(ev, transform);
  232.     }    
  233. }
  234.  
  235. //----------------------------------------------------------------------------------------
  236. // FW_CShapeListShape::MoveShape
  237. //----------------------------------------------------------------------------------------
  238.  
  239. void FW_CShapeListShape::MoveShape(FW_Fixed deltaX, FW_Fixed deltaY)
  240. {
  241.     FW_CShapeListIterator ite(fShapeList);
  242.     for (FW_CShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  243.     {
  244.         shape->MoveShape(deltaX, deltaY);
  245.     }    
  246. }
  247.  
  248. //----------------------------------------------------------------------------------------
  249. // FW_CShapeListShape::MoveShapeTo
  250. //----------------------------------------------------------------------------------------
  251.  
  252. void FW_CShapeListShape::MoveShapeTo(FW_Fixed x, FW_Fixed y)
  253. {
  254.     FW_CPoint shapeListAnchor(GetAnchorPoint());
  255.     FW_CPoint delta(x - shapeListAnchor.x, y - shapeListAnchor.y);
  256.     
  257.     FW_CShapeListIterator ite(fShapeList);
  258.     for (FW_CShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  259.     {
  260.         shape->MoveShape(delta.x, delta.y);
  261.     }    
  262. }
  263.     
  264. //----------------------------------------------------------------------------------------
  265. // FW_CShapeListShape::Inset
  266. //----------------------------------------------------------------------------------------
  267.  
  268. void FW_CShapeListShape::Inset(FW_Fixed h, FW_Fixed v)
  269. {
  270.     FW_CShapeListIterator ite(fShapeList);
  271.     for (FW_CShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  272.     {
  273.         shape->Inset(h, v);
  274.     }    
  275. }
  276.     
  277. //----------------------------------------------------------------------------------------
  278. // FW_CShapeListShape::GetBounds
  279. //----------------------------------------------------------------------------------------
  280.  
  281. void FW_CShapeListShape::GetBounds(FW_CGraphicContext& gc, FW_CRect& rect) const
  282. {
  283.     FW_Boolean first = TRUE;
  284.  
  285.     FW_CShapeListIterator ite(fShapeList);
  286.     for (FW_CShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  287.     {
  288.         FW_CRect bounds;
  289.         shape->GetBounds(gc, bounds);
  290.         if (first)
  291.             rect = bounds;
  292.         else
  293.             rect.Union(bounds);
  294.         first = FALSE;
  295.     }    
  296. }
  297.  
  298. //----------------------------------------------------------------------------------------
  299. //    FW_CShapeListShape::GetAnchorPoint
  300. //----------------------------------------------------------------------------------------
  301.  
  302. FW_CPoint FW_CShapeListShape::GetAnchorPoint() const
  303. {
  304.     return fShapeList->GetAnchorPoint();
  305. }
  306.  
  307. //----------------------------------------------------------------------------------------
  308. // FW_CShapeListShape::Flatten
  309. //----------------------------------------------------------------------------------------
  310.  
  311. void FW_CShapeListShape::Flatten(FW_CWritableStream& stream) const
  312. {
  313.     FW_CShape::Flatten(stream);
  314.     stream << fShapeList;
  315. }
  316.  
  317.